package com.Akronmcp.hta.obj;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class HPar2 extends HPar {

	int ticktime = 4;
	int staytime = 100;
	
	
    boolean endbyhop =false;
    private int cycle = 1;
    
    //前引(前期建立对象并储存,后期替换对象)
    //中引(前期建立指针,后期建立对象并储存)
    //后引(前期建立指针,后期指向已建立对象)
    String module;//中引
    //文字闪烁模板
    
    boolean iscopyedmodule = false;
    //是否已复制模板的特效
    
	private List<String> tht = new ArrayList<String>();
	private List<String[]> thta = new ArrayList<String[]>();//储存种类和参数
    
	List<String> sl = new ArrayList<String>();//特技集合,储存每一帧
	
	public HPar2(HManager hta)
	{
		super(hta);
	}
	
	public HPar2() {}
	
	/**设置帧*/
	public void setFrameList(List<String> l)
	{
		sl = l;
	}
	public List<String> getFrameList()
	{
		return sl;
	}
   
	/**设置是否随一周期闪烁结束而结束*/
	public void setEndByHop(boolean isEndByHop)
	{
		
		endbyhop = isEndByHop;
	}
	
	public boolean isEndByHop() 
	{
		return endbyhop;
	}
	
	/**设置循环周期数*/
	public void setCycle(int cycle)
	{
		this.cycle = cycle;
	}

	/**创建闪烁,参数为闪烁类型,类型对应的参数,由HDancer生成闪烁帧并加入帧列表*/
	public void addTextHop(String type,String...str)
	{
		
		
		 gethoptypes().add(type);//储存种类s
		 getHopargs().add(str);//储存参数s
		
			try {
				HDancer.Dance(sl,type,ticktime,text,str);
				//生成闪烁帧
			} catch (Exception e) {
				e.printStackTrace();
			}
		
		
	}
	
	/**获取持续时间*/
	public int getStayTime()
	{
		return staytime;
	}	
  	public void setStayTime(int time)
	{
		staytime = time;
	}
  	
  	/**获取刷新率*/
	public int getTickTime()
	{
		return ticktime;
	}
	
	/**设置刷新率,单位tick*/
	public void setTickTime(int time)
	{
		ticktime = time;
	}
	
	
	public List<String> gethoptypes() {
		return tht;
	}
	public void setHoptypes(List<String> tht) {
		this.tht = tht;
	}
	public List<String[]> getHopargs() {
		return thta;
	}
	public void setHopargs(List<String[]> thta) {
		this.thta = thta;
	}
	public int getCycle() {
		return cycle;
	}
	
    /**设置闪烁特效模板,将使用模型内的闪烁效果生成闪烁帧*/
	public void setModule(String module)
	{
		 
			HPar2 hp0 = null;
			Map<String, HPar2> m = new HashMap<String, HPar2>();
			m.putAll(HManager.htmlist);
		
		   if(module.equals("auto"))
		   {//当模型为随机,将从模型集合中随机抽取
			   Random r = new Random();
			   int f = r.nextInt(m.size());
			   int i = 0;
			   for(String k:m.keySet())
			   {
				   if(i==f)
				   {
					   hp0 = m.get(k);
					   break;
				   }
				   i++;
			   }
		   }else
		   {
			   hp0 = m.get(module);
		   }
		   
		   HPar2 hp = this;
		   
		   if(hp0!=null)
		   {//重新生成帧
			    hp.setHoptypes(hp0.gethoptypes());
			    hp.setHopargs(hp0.getHopargs());
			    
			    hp.setTickTime(hp0.getTickTime());
			    hp.setEndByHop(hp0.isEndByHop());
			    hp.setText(text);
			    
				if(!hp.gethoptypes().isEmpty())
				{//清空原特效类型和参数
					List<String> thtl = new ArrayList<String>(hp.gethoptypes());
	   			    List<String[]> thtal = new ArrayList<String[]>(hp.getHopargs());
	   			    hp.setHoptypes(new ArrayList<String>());
	    			hp.setHopargs(new ArrayList<String[]>());	
	   			    hp.setFrameList(new ArrayList<String>());
					
	   			int in = 0;
	   			for(String ty:thtl)
	   			{//重新生成帧数
	   				
	   				hp.addTextHop(ty,thtal.get(in));
	   				in++;
	   			}
	   			
				}
				
			    this.module = module;
			    iscopyedmodule = true;
			    
		   }else
		   {
			   this.module = module;
		   }
		   
	}
	
	/**清空闪烁帧*/
	public void clearHop()
	{
		gethoptypes().clear();
		getHopargs().clear();
	}

}
